package com.zkthink.ceres.member.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zkthink.base.mapper.SuperMapper;
import com.zkthink.ceres.member.dto.MemberPageDTO;
import com.zkthink.ceres.member.entity.Member;

import com.zkthink.ceres.member.vo.TuiguangVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 商城会员信息
 * </p>
 *
 * @author kellen
 * @date 2020-05-02
 */
@Repository
public interface MemberMapper extends SuperMapper<Member> {

  IPage<Member> page(IPage page, @Param("model") MemberPageDTO model);

  void updateUserType(@Param("id") Long id,@Param("usertype") Integer userType);

    Member selectByPhone(@Param("phone") String phone);
    @Select("select IFNULL(sum(ticheng),0)  from chl_member_ticheng where mid=#{mid}")
    BigDecimal ticheng(Long mid);
    @Select("select id,nickname,headimg  from ceres_member where refer_phone = #{referPhone}")
    List<TuiguangVo> tuiguang(String referPhone);

  //@Select("select nickname,headimg,xiaofei,ticheng,create_time  from chl_member_ticheng where mid=#{mid} order by create_time desc")
  @Select("SELECT ac.id,cm.nickname, cm.headimg, ac.pay_sum xiaofei, ac.direct_commission ticheng, ac.create_time createtime FROM applet_commission ac INNER JOIN ceres_member cm ON ac.mid = cm.id WHERE cm.refer_phone = (select phone FROM ceres_member cmmm where id = #{mid}) UNION ALL SELECT ac.id,cm.nickname, cm.headimg, ac.pay_sum xiaofei, ac.indirect_commission ticheng, ac.create_time createtime FROM applet_commission ac INNER JOIN ceres_member cm ON ac.mid = cm.id WHERE cm.refer_phone IN ( SELECT phone FROM ceres_member cmm WHERE cmm.refer_phone = (select phone FROM ceres_member cmmm where id = #{mid}) ) ")
  List<TuiguangVo> tuiguangDetails(Long mid);

  @Select("select role_type from ceres_member where id = #{mid} ")
  Long selectRoleTypeById(Long mid);

}
